package hxy.bytecode.stream;

import lombok.Data;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.TreeSet;
import java.util.stream.Collectors;

/**
 * @author eric
 * @date 2021/6/7
 */
public class RemoveDuplicate {

    public static void main(String[] args) {
        List<User> list = new ArrayList<>();
        User u = new User();
        u.setAge(10);
        u.setName("张三");
        list.add(u);
        User u2 = new User();

        u2.setAge(13);
        u2.setName("李四");
        list.add(u2);
        User u3 = new User();
        u3.setAge(13);
        u3.setName("李四");
        list.add(u3);
        list = list.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(s -> s.getName() + ";" + s.getAge()))), ArrayList::new));
        list.forEach(userList -> {
            System.out.println(userList.getName() + userList.getAge());
        });
    }
//————————————————
//    版权声明：本文为CSDN博主「猹里。」的原创文章，遵循CC 4.0 BY-SA版权协议，转载请附上原文出处链接及本声明。
//    原文链接：https://blog.csdn.net/qq_30667039/article/details/102386480
}

@Data
class User {
    int age;
    String name;
}
